package com.test.mchelepesa.activity_fragment_rice;

import static com.test.mchelepesa.constant_rice.Constant_rice.Country_Tanzania;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.test.mchelepesa.R;
import com.test.mchelepesa.activity_fragment_rice.base_rice.BaseActivity_rice;
import com.test.mchelepesa.activity_fragment_rice.base_rice.BaseApplication_rice;
import com.test.mchelepesa.activity_fragment_rice.loan_rice.LoanMainActivity_rice;
import com.test.mchelepesa.bean_rice.StaticConfig_rice;
import com.test.mchelepesa.constant_rice.Constant_rice;
import com.test.mchelepesa.dialog_rice.DeleteDataDialog_rice;
import com.test.mchelepesa.dialog_rice.LanguageDialog_rice;
import com.test.mchelepesa.dialog_rice.LogoutDialog_rice;
import com.test.mchelepesa.util_rice.helper_rice.UserInfoHelper_rice;
import com.test.mchelepesa.util_rice.http_rice.HttpManager_rice;
import com.test.mchelepesa.view_rice.widget_rice.TitleView_rice;

public class SettingActivity_rice extends BaseActivity_rice {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_rice);

        TitleView_rice titleView = findViewById(R.id.setting_title);
        titleView.getBackIb().setOnClickListener(v -> onBackPressed());

        TextView versionTv = findViewById(R.id.setting_tv_version);
        versionTv.setText(getString(R.string.version_desc, BaseApplication_rice.gApplication_rice().getVersionName()));

        initLicense(
                findViewById(R.id.setting_view_license),
                findViewById(R.id.setting_license_logo),
                findViewById(R.id.setting_license_company_name)
        );

        View switchLanguageView = findViewById(R.id.setting_switch_language);

        if (StaticConfig_rice.Select_Country.equalsIgnoreCase(Country_Tanzania)){
            switchLanguageView.setVisibility(View.VISIBLE);
            switchLanguageView.setOnClickListener(v -> {
                HttpManager_rice.getInstance().saveUserBuriedPoint("SETTING_SWITCH_LANGUAGE_CLICK");
                new LanguageDialog_rice(this,true,() -> startActivityForSingleTop_rice(LoanMainActivity_rice.class)).show();
            });
        }else switchLanguageView.setVisibility(View.GONE);

        findViewById(R.id.setting_logout).setOnClickListener(v -> {
            HttpManager_rice.getInstance().saveUserBuriedPoint("SETTING_LOGOUT_CLICK");
            new LogoutDialog_rice(this).show();
        });

        View deleteDataView = findViewById(R.id.setting_delete_data);

        if (UserInfoHelper_rice.getInstance().showDropButton()){
            deleteDataView.setVisibility(View.VISIBLE);
            deleteDataView.setOnClickListener(v -> {
                HttpManager_rice.getInstance().saveUserBuriedPoint("SETTING_DELETE_DATA_CLICK");
                new DeleteDataDialog_rice(this).show();
            });
        }else deleteDataView.setVisibility(View.GONE);

    }

}